<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link rel="stylesheet" href="/layui/css/layui.css" media="all">
  <title>订单评论审核</title>
</head>
<body>
<table class="layui-hide" id="comment" lay-filter="comment"></table>
<script src="/layui/layui.js" charset="utf-8"></script>
<script src="/jquery/jquery-3.5.1.min.js"></script>
<script type="text/html" id="bar">
  <a class="layui-btn layui-btn-xs" lay-event="PASS">通过</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="NO_PASS">拒绝</a>
</script>
<script th:inline="none" type="text/javascript">
  $.ajaxSetup({
    dataType: "json",
    contentType: "application/json",
  });
  layui.use(['table', 'form'], function () {
    let table = layui.table;
    let form = layui.form;
    table.render({
      id: "commentTable",
      elem: '#comment',
      url: "/api/order/comment/audit/page",
      method: 'post',
      title: '订单评论审核信息表',
      cols: [[
        {field: 'id', title: 'id', width: 50,},
        {field: 'customerName', title: '评论人', width: 100},
        {field: 'level', title: '评分', width: 100},
        {field: 'context', title: '评论内容',},
        {field: 'state', templet: "<div>等待审核</div>", title: '状态', width: 100},
        {field: 'createName', title: '创建人', hide: 'true'},
        {field: 'createTime', title: '创建时间', hide: 'true'},
        {field: 'remake', title: '备注', hide: 'true'},
        {fixed: 'right', title: '操作', toolbar: '#bar', width: 130}
      ]],
      page: true,
      request: {
        pageName: 'pageNum', //页码的参数名称，默认：page
        limitName: 'pageSize' //每页数据量的参数名，默认：limit
      },
      response: {
        statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
      },
      parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
        return {
          "code": res.code, //解析接口状态
          "msg": res.message, //解析提示文本
          "count": res.data.total, //解析数据长度
          "data": res.data.records//解析数据列表
        };
      }
    });

    //监听行工具事件
    table.on('tool(comment)', function (obj) {
      let data = obj.data.id;
      let url = "";
      if (obj.event === 'PASS') {
        url = "/api/order/comment/" + data+"/audit/pass";
      } else if (obj.event === 'NO_PASS'){
        url = "/api/order/comment/" + data+"/audit/noPass";
      }
      $.ajax({
        url: url,
        type: "put",
        success: function (data) {
          if (data.code === 200) {
            layer.msg("处理成功");
            // 刷新表单
            table.reload('commentTable', {
              url: '/api/order/comment/audit/page'
            }, true);
          } else {
            layer.msg(data.message);
          }
        }
      });
    });

  });
</script>

</body>
</html>